{
 "cells": [
  {
   "cell_type": "code",
   "execution_count": 6,
   "source": [
    "import os\r\n",
    "import sys\r\n",
    "import getpass\r\n",
    "import time\r\n",
    "\r\n",
    "dir_path = os.path.abspath('')\r\n",
    "deadline_path = os.path.join(dir_path, 'Deadline_py3')\r\n",
    "print(deadline_path)\r\n",
    "sys.path.append(deadline_path)\r\n",
    "\r\n",
    "HOST = '192.168.8.3'\r\n",
    "PORT = 8082\r\n",
    "\r\n",
    "username = getpass.getuser()\r\n",
    "print(username)\r\n",
    "\r\n",
    "try:\r\n",
    "    import DeadlineConnect as Connect\r\n",
    "    connectionObject = Connect.DeadlineCon(HOST, PORT)\r\n",
    "except Exception as Connect_ERR:\r\n",
    "    print('Connect_ERR:',Connect_ERR)"
   ],
   "outputs": [
    {
     "output_type": "stream",
     "name": "stdout",
     "text": [
      "f:\\PycharmOut\\deadline_py3\\Deadline_py3\n",
      "laozhang\n"
     ]
    }
   ],
   "metadata": {}
  },
  {
   "cell_type": "code",
   "execution_count": 9,
   "source": [
    "# 获取Active Jobs\r\n",
    "def get_active_jobs(username=None):\r\n",
    "    start = time.time()\r\n",
    "\r\n",
    "    all_active_jobs = connectionObject.Jobs.GetJobsInState('Active')\r\n",
    "\r\n",
    "    status_map = {0:'Unknown',1:'Active',2:'Suspended',3:'Completed',4:'Failed',6:'Pending'}\r\n",
    "\r\n",
    "    data_list = []\r\n",
    "    for a in all_active_jobs:\r\n",
    "        data = {}\r\n",
    "        Stat = a.get('Stat',0)\r\n",
    "        Props = a.get('Props',{})\r\n",
    "        User = Props.get('User','')\r\n",
    "        Name = Props.get('Name', '')\r\n",
    "        _id = a.get('_id', '')\r\n",
    "        data['Name'] = Name\r\n",
    "        data['User'] = User\r\n",
    "        data['_id'] = _id\r\n",
    "        data['Stat'] = Stat\r\n",
    "        data['status'] = status_map[Stat]\r\n",
    "        if username:\r\n",
    "            if user == username:\r\n",
    "                data_list.append(data)\r\n",
    "        else:\r\n",
    "            data_list.append(data)\r\n",
    "    end = time.time()\r\n",
    "    print('执行速度:',end-start)\r\n",
    "    return data_list\r\n"
   ],
   "outputs": [],
   "metadata": {}
  },
  {
   "cell_type": "code",
   "execution_count": 32,
   "source": [
    "\r\n",
    "active_jobs = get_active_jobs()\r\n",
    "print(len(active_jobs))\r\n",
    "for data in active_jobs:\r\n",
    "    print(data)"
   ],
   "outputs": [
    {
     "output_type": "stream",
     "name": "stdout",
     "text": [
      "执行速度: 0.07297778129577637\n",
      "26\n",
      "{'Name': 'HYX52_01_070_efx_xundaoqiao_v001_wedge0_2021-07-23__11-31-49_ramp_a', 'User': 'huangrui', '_id': '60fa38496798fb23506ea090', 'Stat': 1, 'status': 'Active'}\n",
      "{'Name': 'HYX52_01_070_efx_xundaoqiao_v001_wedge0_2021-07-23__11-31-49_ramp_b', 'User': 'huangrui', '_id': '60fa38496798fb23506ea091', 'Stat': 1, 'status': 'Active'}\n",
      "{'Name': 'HYX52_01_070_efx_xundaoqiao_v001_wedge0_2021-07-23__11-31-49_ramp_c', 'User': 'huangrui', '_id': '60fa38496798fb23506ea092', 'Stat': 1, 'status': 'Active'}\n",
      "{'Name': 'HYX52_01_070_efx_xundaoqiao_v001_wedge0_2021-07-23__11-31-49_ramp_d', 'User': 'huangrui', '_id': '60fa38496798fb23506ea093', 'Stat': 1, 'status': 'Active'}\n",
      "{'Name': 'HYX52_01_070_efx_xundaoqiao_v001_wedge0_2021-07-23__11-31-49_ramp_e', 'User': 'huangrui', '_id': '60fa384a6798fb23506ea094', 'Stat': 1, 'status': 'Active'}\n",
      "{'Name': 'HYX52_01_070_efx_xundaoqiao_v001_wedge0_2021-07-23__11-31-49_ramp_f', 'User': 'huangrui', '_id': '60fa384a6798fb23506ea095', 'Stat': 1, 'status': 'Active'}\n",
      "{'Name': 'HYX52_02_030_efx_fuwen_v001_wedge0_2021-07-23__13-10-45_Fazhen_di_1', 'User': 'huangrui', '_id': '60fa4f786798fb23506ea0a9', 'Stat': 1, 'status': 'Active'}\n",
      "{'Name': 'HYX52_02_030_efx_fuwen_v001_wedge0_2021-07-23__13-10-45_light_di_1', 'User': 'huangrui', '_id': '60fa4f786798fb23506ea0aa', 'Stat': 1, 'status': 'Active'}\n",
      "{'Name': 'HYX52_02_030_efx_fuwen_v001_wedge0_2021-07-23__13-10-45_Fazhen_shou_1', 'User': 'huangrui', '_id': '60fa4f796798fb23506ea0ab', 'Stat': 1, 'status': 'Active'}\n",
      "{'Name': 'HYX52_02_030_efx_fuwen_v001_wedge0_2021-07-23__13-10-45_light_shou_1', 'User': 'huangrui', '_id': '60fa4f796798fb23506ea0ac', 'Stat': 1, 'status': 'Active'}\n",
      "{'Name': 'HYX52_02_030_efx_fuwen_v001_wedge0_2021-07-23__13-10-45_huoxing', 'User': 'huangrui', '_id': '60fa4f796798fb23506ea0ad', 'Stat': 1, 'status': 'Active'}\n",
      "{'Name': 'EP12_S10_C0070_efx_Bht_V003_v002_wedge0_2021-07-23__17-14-49_OUT_Fluid_Compress_01', 'User': 'buht', '_id': '60fa89de6798fb23506ea11c', 'Stat': 1, 'status': 'Active'}\n",
      "{'Name': 'HYX52_02_230_efx_shui_R1_wedge0_2021-07-23__14-09-23_Render_whitewater_six1', 'User': 'niewb', '_id': '60fa60756798fb23506ea0c7', 'Stat': 1, 'status': 'Active'}\n",
      "{'Name': 'HYX52_02_206_001_efx_xuanwujiejie_v009_wedge0_2021-07-23__14-28-32_Shui_two', 'User': 'zhanggl', '_id': '60fa63a96798fb23506ea0cc', 'Stat': 1, 'status': 'Active'}\n",
      "{'Name': 'HYX52_02_206_001_efx_xuanwujiejie_v009_wedge0_2021-07-23__14-28-32_Shui_three', 'User': 'zhanggl', '_id': '60fa63a96798fb23506ea0cd', 'Stat': 1, 'status': 'Active'}\n",
      "{'Name': 'HYX52_02_206_001_efx_xuanwujiejie_v009_wedge0_2021-07-23__14-28-32_Whitewater_one', 'User': 'zhanggl', '_id': '60fa63a96798fb23506ea0ce', 'Stat': 1, 'status': 'Active'}\n",
      "{'Name': 'HYX52_02_206_001_efx_xuanwujiejie_v009_wedge0_2021-07-23__14-28-32_Whitewater_two', 'User': 'zhanggl', '_id': '60fa63a96798fb23506ea0cf', 'Stat': 1, 'status': 'Active'}\n",
      "{'Name': 'HYX52_02_206_001_efx_xuanwujiejie_v009_wedge0_2021-07-23__14-28-32_Whitewater_three', 'User': 'zhanggl', '_id': '60fa63a96798fb23506ea0d0', 'Stat': 1, 'status': 'Active'}\n",
      "{'Name': 'HYX52_02_179_efx_xuanwujiejie_and_shui_v006_wedge0_2021-07-23__16-42-11_MESH_CACHE_Five', 'User': 'dujf', '_id': '60fa814d6798fb23506ea10a', 'Stat': 1, 'status': 'Active'}\n",
      "{'Name': 'HYX52_02_178_efx_xuanwujiejie_and_shui_v005_wedge0_2021-07-23__16-54-50_FLUID_CACHE_v02', 'User': 'dujf', '_id': '60fa84446798fb23506ea113', 'Stat': 1, 'status': 'Active'}\n",
      "{'Name': 'CXRX_pianhua_002_efx_huaban_v003_wedge0_2021-07-23__17-11-00_hua_self', 'User': 'chenyi', '_id': '60fa891e6798fb23506ea116', 'Stat': 1, 'status': 'Active'}\n",
      "{'Name': 'CXRX_pianhua_002_efx_huaban_v003_wedge0_2021-07-23__17-11-00_hua_F', 'User': 'chenyi', '_id': '60fa891e6798fb23506ea117', 'Stat': 1, 'status': 'Active'}\n",
      "{'Name': 'CXRX_pianhua_002_efx_huaban_v003_wedge0_2021-07-23__17-11-00_hua_B', 'User': 'chenyi', '_id': '60fa891e6798fb23506ea118', 'Stat': 1, 'status': 'Active'}\n",
      "{'Name': 'CXRX_pianhua_002_efx_huaban_v003_wedge0_2021-07-23__17-11-00_hua_curve', 'User': 'chenyi', '_id': '60fa891f6798fb23506ea119', 'Stat': 1, 'status': 'Active'}\n",
      "{'Name': 'CXRX_pianhua_002_efx_huaban_v003_wedge0_2021-07-23__17-11-00_hua_big', 'User': 'chenyi', '_id': '60fa891f6798fb23506ea11a', 'Stat': 1, 'status': 'Active'}\n",
      "{'Name': 'HYX52_02_230_efx_shui_R1_wedge0_2021-07-23__15-48-42_FLUID_CACHE_v02', 'User': 'niewb', '_id': '60fa77bb6798fb23506ea0ff', 'Stat': 1, 'status': 'Active'}\n"
     ]
    }
   ],
   "metadata": {}
  },
  {
   "cell_type": "code",
   "execution_count": 34,
   "source": [
    "\"\"\"  *****   Job Reports      *****  \"\"\"\r\n",
    "job_id = '60fa77bb6798fb23506ea0ff'"
   ],
   "outputs": [],
   "metadata": {}
  },
  {
   "cell_type": "code",
   "execution_count": 35,
   "source": [
    "# 获取所有 Job Error Reports Contents\r\n",
    "jer = connectionObject.JobReports.GetAllJobErrorReportsContents(job_id)\r\n",
    "print(jer)"
   ],
   "outputs": [
    {
     "output_type": "stream",
     "name": "stdout",
     "text": [
      "[]\n"
     ]
    }
   ],
   "metadata": {}
  },
  {
   "cell_type": "code",
   "execution_count": 36,
   "source": [
    "# 获取所有 Job Log Reports Contents\r\n",
    "jlr = connectionObject.JobReports.GetAllJobLogReportsContents(job_id)\r\n",
    "print(jlr)"
   ],
   "outputs": [
    {
     "output_type": "stream",
     "name": "stdout",
     "text": [
      "[]\n"
     ]
    }
   ],
   "metadata": {}
  },
  {
   "cell_type": "code",
   "execution_count": 37,
   "source": [
    "# 获取所有Job Reports\r\n",
    "jr = connectionObject.JobReports.GetAllJobReports(job_id)\r\n",
    "print(jr)"
   ],
   "outputs": [
    {
     "output_type": "stream",
     "name": "stdout",
     "text": [
      "[]\n"
     ]
    }
   ],
   "metadata": {}
  },
  {
   "cell_type": "code",
   "execution_count": 38,
   "source": [
    "# 获取所有 Job Reports Contents\r\n",
    "jrc = connectionObject.JobReports.GetAllJobReportsContents(job_id)\r\n",
    "print(jrc)\r\n"
   ],
   "outputs": [
    {
     "output_type": "stream",
     "name": "stdout",
     "text": [
      "[]\n"
     ]
    }
   ],
   "metadata": {}
  },
  {
   "cell_type": "code",
   "execution_count": 39,
   "source": [
    "# 获取所有Job Requeue Reports Contents\r\n",
    "jrrc = connectionObject.JobReports.GetAllJobRequeueReportsContents(job_id)\r\n",
    "print(jrrc)"
   ],
   "outputs": [
    {
     "output_type": "stream",
     "name": "stdout",
     "text": [
      "[]\n"
     ]
    }
   ],
   "metadata": {}
  },
  {
   "cell_type": "code",
   "execution_count": 40,
   "source": [
    "# 获取 Job Log Reports\r\n",
    "jlr = connectionObject.JobReports.GetJobLogReports(job_id)\r\n",
    "print(jlr)"
   ],
   "outputs": [
    {
     "output_type": "stream",
     "name": "stdout",
     "text": [
      "[]\n"
     ]
    }
   ],
   "metadata": {}
  },
  {
   "cell_type": "code",
   "execution_count": 41,
   "source": [
    "# 获取 Job Error Reports\r\n",
    "jer = connectionObject.JobReports.GetJobErrorReports(job_id)\r\n",
    "print(jer)\r\n"
   ],
   "outputs": [
    {
     "output_type": "stream",
     "name": "stdout",
     "text": [
      "[]\n"
     ]
    }
   ],
   "metadata": {}
  },
  {
   "cell_type": "code",
   "execution_count": 60,
   "source": [
    "# 获取 Tasks\r\n",
    "\r\n",
    "tasks = connectionObject.Tasks.GetJobTasks(job_id)\r\n",
    "print(tasks)"
   ],
   "outputs": [
    {
     "output_type": "stream",
     "name": "stdout",
     "text": [
      "{'ID': '60fa77bb6798fb23506ea0ff', 'PreTask': None, 'Tasks': [{'JobID': '60fa77bb6798fb23506ea0ff', 'TaskID': 0, 'Frames': '150-370', 'Slave': 'xuanran21', 'Stat': 4, 'Prog': '96 %', 'RndStat': 'Progress: 96.0 %', 'Errs': 0, 'Start': '2021-07-23T16:05:14.04+08:00', 'StartRen': '2021-07-23T16:05:21.355+08:00', 'Comp': '0001-01-01T00:00:00Z', 'WtgStrt': False, 'NormMult': 1.0, 'Size': 0, 'RamPeak': 30215372800, 'RamPeakPer': 23, 'Cpu': 102, 'CpuPer': 62, 'RamAvg': 18905939968, 'RamAvgPer': 14, 'SwapAvg': 2792586, 'SwapPeak': 2825080, 'UsedClock': 341033600, 'TotalClock': 550054208, 'Props': {'Ex0': '', 'Ex1': '', 'Ex2': '', 'Ex3': '', 'Ex4': '', 'Ex5': '', 'Ex6': '', 'Ex7': '', 'Ex8': '', 'Ex9': '', 'ExDic': {}}, '_id': '60fa77bb6798fb23506ea0ff_0', 'ExtraElements': None}], 'PostTask': None}\n"
     ]
    }
   ],
   "metadata": {}
  },
  {
   "cell_type": "code",
   "execution_count": 43,
   "source": [
    "task_id = 0\r\n",
    "tlogs = connectionObject.TaskReports.GetTaskLogReports(job_id,task_id)\r\n",
    "print(tlogs)"
   ],
   "outputs": [
    {
     "output_type": "stream",
     "name": "stdout",
     "text": [
      "[]\n"
     ]
    }
   ],
   "metadata": {}
  },
  {
   "cell_type": "code",
   "execution_count": 44,
   "source": [
    "# 获取 Task Error Reports\r\n",
    "telogs = connectionObject.TaskReports.GetTaskErrorReports(job_id,task_id)\r\n",
    "print(telogs)"
   ],
   "outputs": [
    {
     "output_type": "stream",
     "name": "stdout",
     "text": [
      "[]\n"
     ]
    }
   ],
   "metadata": {}
  },
  {
   "cell_type": "code",
   "execution_count": 17,
   "source": [
    "# 获取所有 Task Logs Reports Contents\r\n",
    "tclogs = connectionObject.TaskReports.GetAllTaskLogReportsContents(job_id,task_id)\r\n",
    "print(tclogs)"
   ],
   "outputs": [
    {
     "output_type": "stream",
     "name": "stdout",
     "text": [
      "[]\n"
     ]
    }
   ],
   "metadata": {}
  },
  {
   "cell_type": "code",
   "execution_count": 19,
   "source": [
    "# 获取所有 Task Reports\r\n",
    "tr = connectionObject.TaskReports.GetAllTaskReports(job_id,task_id)\r\n",
    "print(tr)\r\n"
   ],
   "outputs": [
    {
     "output_type": "stream",
     "name": "stdout",
     "text": [
      "[]\n"
     ]
    }
   ],
   "metadata": {}
  },
  {
   "cell_type": "code",
   "execution_count": 20,
   "source": [
    "# 获取所有 Task Error Reports Contents\r\n",
    "ter = connectionObject.TaskReports.GetAllTaskErrorReportsContents(job_id,task_id)\r\n",
    "print(ter)"
   ],
   "outputs": [
    {
     "output_type": "stream",
     "name": "stdout",
     "text": [
      "[]\n"
     ]
    }
   ],
   "metadata": {}
  }
 ],
 "metadata": {
  "orig_nbformat": 4,
  "language_info": {
   "name": "python",
   "version": "3.7.1",
   "mimetype": "text/x-python",
   "codemirror_mode": {
    "name": "ipython",
    "version": 3
   },
   "pygments_lexer": "ipython3",
   "nbconvert_exporter": "python",
   "file_extension": ".py"
  },
  "kernelspec": {
   "name": "python3",
   "display_name": "Python 3.7.1 64-bit ('Python3_7_2')"
  },
  "interpreter": {
   "hash": "ceed3ede7d2ae4746b1bde0ed48f83d28ba93d0b68e140a25bb2fbb7cbabeb22"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 2
}